home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / T / TC Prog Guide.cpt / picture ƒ / coord.c < prev    next >
Text File  |  1990-11-08  |  2KB  |  87 lines

  1. /*
  2. *    FILE:        coord.c
  3. *    AUTHOR:        R. Gonzalez
  4. *    CREATED:    October 4, 1990
  5. *
  6. *    methods for 2D and 3D coordinates
  7. */
  8.  
  9. # include    "coord.h"
  10.  
  11. /******************************************************************
  12. *    initialize
  13. ******************************************************************/
  14. boolean    Coord2::init(void)
  15. {
  16.     set(0.,0.);
  17.     
  18.     return TRUE;
  19. }
  20.  
  21. /******************************************************************
  22. *    set values
  23. ******************************************************************/
  24. void    Coord2::set(double x_val,double y_val)
  25. {
  26.     x = x_val;
  27.     y = y_val;
  28. }
  29.  
  30. /******************************************************************
  31. *    convert 2D coordinate from one frame into a new one
  32. ******************************************************************/
  33. void    Coord2::convert(Coord2* c,Frame* old_frame,Frame* new_frame)
  34. {
  35.     double    ratio;
  36.     
  37.     ratio = new_frame->width/old_frame->width;
  38.     x = new_frame->x + (c->x-old_frame->x) * ratio;
  39.     
  40.     ratio = new_frame->height/old_frame->height;
  41.     y = new_frame->y + (c->y-old_frame->y) * ratio;
  42. }
  43.  
  44. /******************************************************************
  45. *    initialize
  46. ******************************************************************/
  47. boolean    Coord3::init(void)
  48. {
  49.     set(0.,0.,0.);
  50.     
  51.     return TRUE;
  52. }
  53.  
  54. /******************************************************************
  55. *    set values
  56. ******************************************************************/
  57. void    Coord3::set(double x_val,double y_val,double z_val)
  58. {
  59.     x = x_val;
  60.     y = y_val;
  61.     z = z_val;
  62. }
  63.  
  64. /******************************************************************
  65. *    applies the transformation to the coordinate.  This is done
  66. *    by converting the 3D point to a 4D homogeneous coordinate and
  67. *    right-multiplying it by the 4D homogeneous transformation
  68. *    matrix to produce a new point.
  69. ******************************************************************/
  70. void    Coord3::apply(Coord3* c,Transformation* t)
  71. {
  72.     x = c->x*t->m[0][0] + c->y*t->m[1][0] + c->z*t->m[2][0] + t->m[3][0];
  73.     y = c->x*t->m[0][1] + c->y*t->m[1][1] + c->z*t->m[2][1] + t->m[3][1];
  74.     z = c->x*t->m[0][2] + c->y*t->m[1][2] + c->z*t->m[2][2] + t->m[3][2];
  75. }
  76.  
  77. /******************************************************************
  78. *    set coord equal to another.
  79. ******************************************************************/
  80. void    Coord3::equate(Coord3* c)
  81. {
  82.     x = c->x;
  83.     y = c->y;
  84.     z = c->z;
  85. }
  86.  
  87.